jQ(function(){
	jQ("div.my_clips_menu a.clipmanage").addClass("clipmanageonit");
	jQ("input.hminput").val(0);
	jQ("#replycontent").val("");
	var eventid=eval(getParameter("eventid"));
	if(isNaN(eventid)||eventid==null){
		window.location.href=jQ("#ctxVal").val()+"/myclip/clip_remind.html";
	}else{
		getClipDetail(eventid);
	}
	jQ("#left_clip_list").empty();
	jQ("#mainpart_list_content").data("currentpage",0);
	initLeftCalendar();
	loadTodayEvents();
	reloadCacheAndClockCount();
	initContactGroups();
	jQ("#viewopt").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:false,
		height:200,
		buttons: {
			
			"确定": function() {
				var opt=jQ("#viewopt");
				var triggerfun=opt.data("function");
				opt.trigger(triggerfun);
				opt.removeData("function");
				jQ("#viewopt_p").hide();
				jQ("#viewopt_img").show();
				activeBtnOnDialog("viewopt",false);
				//jQ(this).dialog('close');
			},
			"取消": function() {
				var viewopt=jQ("#viewopt");
				var triggerfun=jQ("#viewopt").data("function");
				viewopt.unbind(triggerfun);
				viewopt.find("input.eventid").val("");
				viewopt.removeData("function");
				jQ(this).dialog('close');
			}
		},
		close: function() {
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
			activeBtnOnDialog("viewopt",true);
		},
		open:function(){
			
		}
	});
});

function initContactGroups(){
	jQ.ajax({
		type:"POST",
		url: "contactAjax!getExistGroupAndContacts.action",
		success:function(data){
			if(data!=null){
				var source = jQ( "ContactGroup ", data ).map(function() {
					return {
						label: jQ("groupname", this).text(),
						id: jQ(this).attr("id"),
						value:jQ("pinyingroupname", this).text()
					};
				}).get();
				jQ( "#shareautoipt" ).autocomplete({
					source: source,
					minLength:1,
					select: function( event, ui ) {
						if(ui.item){
							showQuickContactGroup(ui.item.id,ui.item.label);
						}
					},
					close: function() {
						jQ( "#shareautoipt" ).val("");
					}
				}).data( "autocomplete" )._renderItem = function( ul, item ) {
				return jQ( "<li></li>" )
					.data( "item.autocomplete", item )
					.append( "<a>" + item.label +"</a>" )
					.appendTo( ul );
				};
				
			}
		}
	});
	
}


function showQuickContactGroup(id,name){
	var flag=false;
	if(jQ("#contactgrouplist").css("display")=="none"){
		flag=true;
	}
	var canbeadd=true;
	jQ("li",jQ("#contactgrouplist")).each(function(){
		var groupid=eval(jQ(this).attr("groupid"));
		if(groupid==eval(id)){
			canbeadd=false;
			return false;
		}
	});
	if(!canbeadd)
		return;
	var html="<li groupid='"+id+"'>";
	html+="<span class=\"groupicon\"></span>";
	html+="<span class=\"groupname\">"+name+"</span>";
	html+="<a onclick='deleteContactGroup(this);'></a></li>";
	jQ("#contactgrouplist").append(html);
	if(jQ("#contactgrouplist").css("display")=="none"){
		jQ("#contactgrouplist").show();
	}
}

function deleteContactGroup(obj){
	var groupid=jQ(obj).parent().attr("groupid");
	var li=jQ("#contactgroup li[groupid="+groupid+"]");
	li.find("input:checkbox").attr("checked",false);
	jQ(obj).parent().remove();
	if(jQ("li",jQ("#contactgrouplist")).length==0){
		jQ("#contactgrouplist").hide();
	}
}

function reloadCacheAndClockCount(){
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!loadCacheAndClockAndRecycleCount.action",
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(eval(dataObj.result)){
					var clocktotalcount=eval(dataObj.clocktotalcount);
					jQ("#clipevent_clocknum").empty().append("("+clocktotalcount+")");
					var cachetotalcount=eval(dataObj.cachetotalcount);
					jQ("#clipevent_cachenum").empty().append("("+cachetotalcount+")");
					var recycletotalcount=eval(dataObj.recycletotalcount);
					jQ("#clipevent_recyclenum").empty().append("("+recycletotalcount+")");
				}
			}
		}
	});
}

function getClipDetail(eventid){
	jQ.ajax({
		type:"POST",
		url: "manageClipAjax!loadMyclips.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null&&typeof(data)!='string'){
				var mobilenotice=eval(jQ(data).find("mobilenotice").text());
				if(mobilenotice==1){
					jQ(".hasmobilechoose").show();
				}else{
					jQ(".hasmobilechoose").hide();
				}
				jQ("#clipevent-maincontent").show();
				var eventid=eval(jQ(data).find("EventForView").attr("id"));
				loadClipMessage(eventid);
				var title=jQ(data).find("EventForView").find("title").text();
				var eventtype=jQ(data).find("EventForView").find("eventtype").text();
				var starttime=eval(jQ(data).find("EventForView").find("starttime").text());
				var endtime=eval(jQ(data).find("EventForView").find("endtime").text());
				var iswholeday=eval(jQ(data).find("EventForView").find("iswholeday").text());
				var address=jQ(data).find("EventForView").find("address").text();
				var content=jQ(data).find("EventForView").find("content").text();
				var clocktime=eval(jQ(data).find("EventForView").find("clocktime").text());
				var deadlinetime=eval(jQ(data).find("EventForView").find("deadlinetime").text());
				var isexpire=eval(jQ(data).find("EventForView").find("isexpire").text());
				var isvip=eval(jQ(data).find("EventForView").find("isvip").text());
				var processstatus=eval(jQ(data).find("EventForView").find("processstatus").text());
				var clipstatus=eval(jQ(data).find("EventForView").find("clipstatus").text());
				var reliedclip=eval(jQ(data).find("EventForView").find("reliedclip").text());
				var fuid=eval(jQ(data).find("EventForView").find("fuid").text());
				var uname=jQ(data).find("EventForView").find("uname").text();
				var pname=jQ(data).find("EventForView").find("pname").text();
				var cliptype=eval(jQ(data).find("EventForView").find("cliptype").text());
				
				var allcount=jQ(data).find("EventForView").find("contact").length;
				jQ("#invitednum").empty().append(allcount);
				if(cliptype==3){
					var countsharesave=jQ(data).find("EventForView").find("countsharesave").text();
					var countshareforward=jQ(data).find("EventForView").find("countshareforward").text();
					jQ("#savesharenum").empty().append(countsharesave);
					jQ("#forwardsharenum").empty().append(countshareforward);
				}
				var joincount=0;
				var rejectcount=0;
				var joinH="";
				var refuseH="";
				var no_joinH="";
				jQ(data).find("EventForView").find("contact").each(function(){
					var contactuid=jQ(this).attr("uid");
					var name=jQ(this).find("name").text();
					var email=jQ(this).find("email").text();
					var status=eval(jQ(this).find("status").text());
					var realname=jQ(this).find("realname").text();
					var tmp="";
					tmp+="<input type='hidden' class='contactuid' value='"+contactuid+"'/>";
					tmp+="<div class='name'><span>"+name+"</span><span class='real'>( "+realname+" )</span></div>";
					tmp+="<div class='mail'>"+email+"</div></li>";
					if(status==1){
						joincount++;
						joinH+="<li class='join' title='参加'>"+tmp;
					}else if(status==2){
						rejectcount++;
						refuseH+="<li class='refuse' title='拒绝'>"+tmp;
					}else{
						no_joinH+="<li class='no_join' title='暂无回应'>"+tmp;
					}
					
				});
				if(joinH.length==0&&refuseH.length==0&&no_joinH.length==0){
					jQ("#clipevent-contacts").empty().append("<li style='width:188px;'><i>暂无成员</i></li>");
				}else{
					jQ("#clipevent-contacts").empty().append(joinH).append(refuseH).append(no_joinH);
				}
				jQ("#joinednum").empty().append(joincount);
				jQ("#refusednum").empty().append(rejectcount);
				
				jQ("#clipevent-eventid").val(eventid);
				jQ("#clipevent-clocktime").val(clocktime);
				jQ("#clipevent-title").empty().append(htmlData(title));
				if(isvip){
					jQ("#clipevent-isvip").removeClass().addClass("c_import").attr("title","重要档期");
				}else{
					jQ("#clipevent-isvip").removeClass().addClass("import").attr("title","不重要档期");
				}

				
				if(reliedclip==0||fuid==0){
					jQ("#clipevent-forwardname").parent().parent().hide();
					var unameid=jQ(data).find("EventForView").find("unameid").text();
					var unamelogo=jQ(data).find("EventForView").find("unamelogo").text();
					jQ("#clipevent-publishname").empty().append(
						"<a href='"+jQ("#ctxVal").val()+"/home/user.html?"+unameid+"'>"+uname+"</a>"
					);
					jQ("#clipevent-publishnamelogo").css({"background":"url('"+unamelogo+"')"});
					jQ("#clipevent-publishnamelogo").unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/home/user.html?"+unameid;
					});
				}else{
					var pnameid=jQ(data).find("EventForView").find("pnameid").text();
					var unameid=jQ(data).find("EventForView").find("unameid").text();
					var unamelogo=jQ(data).find("EventForView").find("unamelogo").text();
					var pnamelogo=jQ(data).find("EventForView").find("pnamelogo").text();
					jQ("#clipevent-forwardname").parent().parent().show();
					jQ("#clipevent-forwardname").empty().append(
							"<a href='"+jQ("#ctxVal").val()+"/home/user.html?"+unameid+"'>"+uname+"</a>"
					).parent().show();
					jQ("#clipevent-publishname").empty().append(
							"<a href='"+jQ("#ctxVal").val()+"/home/user.html?"+pnameid+"'>"+pname+"</a>"	
							
					);
					jQ("#clipevent-forwardnamelogo").css({"background":"url('"+unamelogo+"')"});
					jQ("#clipevent-forwardnamelogo").unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/home/user.html?"+unameid;
					});
					jQ("#clipevent-publishnamelogo").css({"background":"url('"+pnamelogo+"')"});
					jQ("#clipevent-publishnamelogo").unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/home/user.html?"+pnameid;
					});
				}
				
				if(cliptype==3){
					jQ("#share_button").show();
				}else{
					jQ("#share_button").hide();
				}
				jQ("#clipevent-eventtype-icon").removeClass().addClass("event").addClass(eventtype);
				jQ("#clipevent-eventtype-typename").empty().append(getTypeName(eventtype));
				
				if(iswholeday)
					jQ("#clipevent-eventtime").empty().append("<span style='width:auto;padding-top:0px;'>开始于</span><b>"+formateDetailTime(starttime)+"</b>");
				else
					jQ("#clipevent-eventtime").empty().append("<b>"+formateDetailTime(starttime)+"</b><b>至</b><b>"+formateDetailTime(endtime)+"</b>");
				if(processstatus==0){
					jQ("#clipevent-processtatus").removeClass().addClass("edt_ing").empty().append("进行中");
				}else if(processstatus==1){
					jQ("#clipevent-processtatus").removeClass().addClass("edt_over").empty().append("已结束");
				}else if(processstatus==2){
					jQ("#clipevent-processtatus").removeClass().addClass("edt_stop").empty().append("已停止");
				}
				if(deadlinetime>0){
					jQ("#clipevent-deadlinetime").empty().append(formateDetailTime(deadlinetime));
					if(isexpire){
						jQ("#clipevent-isexpire").empty().append("已过期").addClass("expire").show();
					}
				}else
					jQ("#clipevent-deadlinetime").empty().append("<i>暂无</i>");
				
				if(clocktime>0){
					jQ("#clipevent-clockval").empty().append(formateDetailTime(clocktime));
					jQ("#clipevent-clockicon").removeClass().addClass("c_alarm").attr("title","关闭提醒");
					jQ("#clipevent-clockicon").unbind("click").bind("click",cancelClockForDetail);
				}else{
					jQ("#clipevent-clockval").empty().append("<i>暂无</i>");
					jQ("#clipevent-clockicon").removeClass().addClass("alarm").attr("title","设置提醒");
					jQ("#clipevent-clockicon").unbind("click").bind("click",addClockForDetail);
				}
				jQ("#clipevent-address").empty().append(htmlData(address));
				jQ("#clipevent-content").empty().append(content);
				if(reliedclip==0){
					jQ("div.modifyopt").show();
					jQ("div.modifyopt").unbind("click").bind("click",modifyDetailEvent);
				}else{
					jQ("div.modifyopt").hide();
				}
				if(processstatus==2){
					if(reliedclip>0&&clipstatus==1)
						jQ("#clipevent-opt a.delete").show();
					else
						jQ("#clipevent-opt a.del").show();
				}else if(processstatus==1){
					if(reliedclip>0&&clipstatus==1)
						jQ("#clipevent-opt a.delete").show();
					else
						jQ("#clipevent-opt a.del").show();
					jQ("#clipevent-opt a.over").show();
				}else{
					if(reliedclip==0){
						jQ("#clipevent-opt a.del").show();
					}else{
						if(clipstatus==0){
							jQ("#clipevent-opt a.join").show();
							jQ("#clipevent-opt a.reject").show();
							jQ("#clipevent-opt a.ignore").show();
						}else if(clipstatus==1){
							jQ("#clipevent-opt a.undo").show();
						}
					}
				}
				initDetailTimeSelect();
				initDetailOptBtn();
				initStatButton(cliptype,eventid);
			}else{
				jQ("#clipevent-maincontent").hide();
				jQ("#clipevent-title").empty().append("<i style='color:#ff0000;'>对不起，该档期不存在或您无权访问。</i>")
			}
		}
	});
}

function initStatButton(cliptype,eventid){
	if(cliptype==3){
		var cureventid=eventid;
		jQ("#share_button").unbind("click").bind("click",function(){
			if(jQ(this).find("a").hasClass("onit")){
				return;
			}else{
				jQ(this).find("a").removeClass().addClass("onit");
				jQ("#invite_button").find("a").removeClass().addClass("outit");
				jQ("#invite_statpart").hide();
				loadCurrentUserContactInShare(cureventid);
				jQ("#share_statpart").show();
			}
		});
		jQ("#invite_button").unbind("click").bind("click",function(){
			if(jQ(this).find("a").hasClass("onit")){
				return;
			}else{
				jQ(this).find("a").removeClass().addClass("onit");
				jQ("#share_button").find("a").removeClass().addClass("outit");
				jQ("#share_statpart").hide();
				jQ("#invite_statpart").show();
			}
		});
	}
}

function loadCurrentUserContactInShare(eventid){
		jQ.ajax({
			type: "POST",
			url:"shareAjax!loadsfFriends.action",
			data:{
				eventid:eval(eventid)
			},
			success:function(data){
				if(data!=null){
					var length=jQ(data).find("User").length;
					jQ("#friendscount").empty().append(length);
					if(length==0){
						jQ("#checkfriendsbtn").hide();
					}else{
						var html="";
						jQ(data).find("User").each(function(i){
							var nickname=jQ(this).find("nickname").text();
							var realname=jQ(this).find("realname").text();
							var uid=jQ(this).attr("uid");
							if(i<6){
								html+="<li index="+i+" class=\"list\">";
							}else{
								html+="<li style='display:none;' index="+i+" class=\"list\">";
							}
							html+="<a href='"+jQ("#ctxVal").val()+"/home/user.html?"+uid+"'>";
							html+="<span class='nickname'>"+nickname+"</span>";
							html+="<span class='out'>( <span class='realname'>"+realname+"</span> )</span>";
							html+="</a>";
							html+="</li>";
						});
						if(jQ(data).find("User").length>6){
							html+="<li class=\"paging\"><a class=\"next\" title=\"下页\"></a><a class=\"prev\" title=\"上页\"></a></li>";
						}
						jQ("#friendslist").empty().append(html).hide();
						if(jQ(data).find("User").length>6){
							var maxcount=jQ(data).find("User").length;
							jQ("#friendslist").data("page",0);
							jQ("#friendslist").data("maxcount",maxcount);
							jQ("#friendslist").data("maxpage",Math.ceil(maxcount/6));
							jQ("#friendslist li.paging a.next").unbind("click").bind("click",shareFriendsNextPage);
							jQ("#friendslist li.paging a.prev").unbind("click").bind("click",shareFriendsPrevPage);
						}
						jQ("#checkfriendsbtn").show().unbind("click").bind("click",showfriendsaboutshare);
					}
				}
			}
		});
}

function shareFriendsNextPage(){
	var page=eval(jQ("#friendslist").data("page"));
	var maxpage=eval(jQ("#friendslist").data("maxpage"));
	var maxcount=eval(jQ("#friendslist").data("maxcount"));
	if(page+1>=maxpage){
		return;
	}else{
		for(var i=0;i<6;i++){
			var index=page*6+i;
			jQ("#friendslist li[index="+index+"]").fadeOut("normal",function(){
				var temp=eval(jQ(this).attr("index"));
				if(temp+6<maxcount){
					jQ("#friendslist li[index="+(temp+6)+"]").fadeIn();
				}
			});
		}
		jQ("#friendslist").data("page",page+1);
	}
}

function shareFriendsPrevPage(){
	var page=eval(jQ("#friendslist").data("page"));
	var maxcount=eval(jQ("#friendslist").data("maxcount"));
	if(page-1<0){
		return;
	}else{
		var index=page*6;
		for(var i=5;i>=0;i--){
			var index=page*6+i;
			if(index>=maxcount){
				jQ("#friendslist li[index="+(index-6)+"]").fadeIn();
			}
			jQ("#friendslist li[index="+index+"]").fadeOut("normal",function(){3
				var temp=eval(jQ(this).attr("index"));
				if(temp-6>=0){
					jQ("#friendslist li[index="+(temp-6)+"]").fadeIn();
				}
			});
		}
		jQ("#friendslist").data("page",page-1);
	}
	
}

function showfriendsaboutshare(){
	if(jQ("#checkfriendsbtn").hasClass("checkfriendsopened")){
		jQ("#checkfriendsbtn").removeClass("checkfriendsopened");
		jQ("#friendslist").hide();
	}else{
		jQ("#checkfriendsbtn").addClass("checkfriendsopened");
		jQ("#friendslist").show();
	}
}

function loadClipMessage(eventid){
	jQ.ajax({
		type: "POST",
		url:"eventAjax!loadClipMessage.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				if(jQ(data).find("Clipmessage").length==0){
					return;
				}
				var html="";
				jQ(data).find("Clipmessage").each(function(){
					var content=jQ("content",this).text();
					var email=jQ(this).find("email").text();
					var replytime=eval(jQ(this).find("replytime").text());
					var name=jQ(this).find("name").text();
					var uid=jQ(this).find("uid").text();
					var logo=jQ(this).find("logo").text();
					var replystr=formateDetailTime(replytime);
					var tmp="<li class='leave_msg'>";
					tmp+="<dt>";
					tmp+="<a class='logo' style='background:url(\""+logo+"\")' href='"+jQ("#ctxVal").val()+"/home/user.html?"+uid+"'></a>";
					tmp+="<span class='fid'>";
					tmp+="<a href='"+jQ("#ctxVal").val()+"/home/user.html?"+uid+"'>"+name+"</a>";
					tmp+="</span>";
					tmp+="<div>";
					tmp+=htmlData(content);
					tmp+="</div>";
					tmp+="<span class='time'>";
					tmp+=replystr;
					tmp+="</span></dt>";
					tmp+="</li>";
					html+=tmp;
				});
				jQ("#clipevent-messages").empty().append(html);
			}
		}
	});
}

function submitReply(){
	var content=jQ.trim(jQ("#replycontent").val());
	if(content==null||content.length==0){
		jQ("#replyzoneerror").empty().append("回复内容不能为空。");
	}else{
		if(content.length>255){
			jQ("#replyzoneerror").empty().append("回复内容不能超过255个字符。");
		}else{
			jQ.ajax({
				type: "POST",
				url:"eventAjax!addreply.action",
				data:{
					eventid:eval(jQ("#clipevent-eventid").val()),
					content:content
				},
				success:function(data){
					if(data!=null){
						var dataObj=eval("("+data+")");//转换为json对象
						if(dataObj.result){
							var name="我";
							var replystr=formateDetailTime(dataObj.replytime);
							var tmp="<li class='leave_msg'>";
							tmp+="<dt>";
							tmp+="<span class='fid'>";
								tmp+=name;
							tmp+="</span>";
							tmp+="<div>";
							tmp+=htmlData(content);
							tmp+="</div>";
							tmp+="<span class='time'>";
							tmp+=replystr;
							tmp+="</span></dt>";
							tmp+="</li>";
							jQ("#clipevent-messages").append(tmp);
							jQ("#replycontent").val("");
						}else{
							jQ("#replyzoneerror").empty().append(dataObj.msg);
						}
					}
				}
			});
		}
	}
}

function initDetailOptBtn(){
	var del=jQ("#clipevent-opt a.del");
	var join=jQ("#clipevent-opt a.join");
	var reject=jQ("#clipevent-opt a.reject");
	var ignore=jQ("#clipevent-opt a.ignore");
	var undo=jQ("#clipevent-opt a.undo");
	var deletejoin=jQ("#clipevent-opt a.delete");
	if(del.css("display")!='none'){
		del.unbind("click").bind("click",deleteDetailEvent);
	}
	if(join.css("display")!='none'){
		join.unbind("click").bind("click",joinDetailEvent);
	}
	if(reject.css("display")!='none'){
		reject.unbind("click").bind("click",rejectDetailEvent);
	}
	if(ignore.css("display")!='none'){
		ignore.unbind("click").bind("click",ignoreDetailEvent);
	}
	if(undo.css("display")!='none'){
		undo.unbind("click").bind("click",deleteDetailEvent);
	}
	if(deletejoin.css("display")!='none'){
		deletejoin.unbind("click").bind("click",deleteDetailEvent);
	}
}

function modifyDetailEvent(){
	var eventid=jQ("#clipevent-eventid").val();
	var info="";
	var title="";
	info="修改档期将删除原先的档期，创建新的档期，确定继续么？";
	title="修改档期";
	var eventid=jQ("#clipevent-eventid").val();
	jQ("#viewopt_eventid").val(eventid);
	var opt=jQ("#viewopt");
	opt.bind("modifyEvent",modifyEvent);
	opt.data("function","modifyEvent")
	jQ("#viewopt_p").empty().append(info);
	jQ("#viewopt").dialog( "option", "title",title );
	jQ("#viewopt").dialog("open");
}

function modifyEvent(){
	var eventid=jQ("#viewopt_eventid").val(); 
	jQ.ajax({
		type: "POST",
		url:"eventAjax!modifyEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					window.location.href=jQ("#ctxVal").val()+"/myclip/add_clip.html?eventid=0";
					jQ("#viewopt").dialog("close");
				}else{
					jQ("#viewopt_p").empty().append(dataObj['msg']);
					jQ("#viewopt").dialog("close");
				}
			}
		}
	});
}

function deleteDetailEvent(event){
	var info="";
	var title="";
	if(jQ(event.currentTarget).hasClass("undo")){
		info="您确定退出档期么？";
		title="退出档期";
	}else if(jQ(event.currentTarget).hasClass("del")){
		info="您确定取消档期么？";
		title="取消档期";
	}else if(jQ(event.currentTarget).hasClass("delete")){
		info="您确定删除档期么？";
		title="删除档期";
	}
	var eventid=jQ("#clipevent-eventid").val();
	jQ("#viewopt_eventid").val(eventid);
	var opt=jQ("#viewopt");
	opt.bind("deleteEvent",deleteEvent);
	opt.data("function","deleteEvent")
	jQ("#viewopt_p").empty().append(info);
	jQ("#viewopt").dialog( "option", "title",title );
	jQ("#viewopt").dialog("open");
}

function deleteEvent(){
	var eventid=jQ("#viewopt_eventid").val(); 
	jQ.ajax({
		type: "POST",
		url:"eventAjax!deleteEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#clipevent-opt a").unbind("click");
					jQ("#viewopt").dialog("close");
					backPage();
				}else{
					jQ("#viewopt_p").empty().append(dataObj['msg']);
					jQ("#viewopt").dialog("close");
				}
			}
		}
	});
}

function joinDetailEvent(){
	var eventid=eval(jQ("#clipevent-eventid").val());
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!acceptInvitedClip.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				jQ("#clipevent-opt a").unbind("click");
				backPage();
			}
		}
	});
}

function rejectDetailEvent(event){
	var eventid=eval(jQ("#clipevent-eventid").val());
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!refuseInvitedClip.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#clipevent-opt a").unbind("click");
					invitingOptReturnBox(event.currentTarget,"拒绝的档期已放入回收站");
				}
			}
		}
	});
}

function ignoreDetailEvent(event){
	var eventid=eval(jQ("#clipevent-eventid").val());
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!ignoreInvitedClip.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#clipevent-opt a").unbind("click");
					invitingOptReturnBox(event.currentTarget,"忽略的档期已放入回收站");
					
				}
			}
		}
	});
}

function invitingOptReturnBox(obj,content){
	var obj_box = jQ(obj);
	var obj_offset = obj_box.offset();
	var msg_box = jQ("#accept_msg_box");
	jQ("#accept_msg_box_content").empty().append(content);
	var _top = obj_offset.top - msg_box.outerHeight() - 10;
	var _left = obj_offset.left - msg_box.outerHeight()/2;
	msg_box.css({"top":_top+"px","left":_left+"px"}).show();
	msg_box.find("div.msg_note").animate({top: 20+'px'}, 500,function(){
		setTimeout(function(){
			msg_box.find("div.msg_note").animate({top: 100+'px'},500,function(){msg_box.hide();backPage();});
		},2000);
	});
}

function initDetailTimeSelect(){
	jQ("tr.clipevent-set_clock td select.time_hour").empty();
	var html="";
	for(var i=0;i<24;i++){
		if(i==0)
			html+="<option value="+i+">0"+i+"</option>";
		else if(i<10)
			html+="<option value="+i+">0"+i+"</option>";
		else
			html+="<option value="+i+">"+i+"</option>";
	}
	jQ("tr.clipevent-set_clock td select.time_hour").append(html);
	html="";
	jQ("tr.clipevent-set_clock td select.time_min").empty();
	for(var i=0;i<12;i++){
		var j=i*5;
		if(j==0)
			html+="<option value="+j+">0"+j+"</option>";
		else if(j<10)
			html+="<option value="+j+">0"+j+"</option>";
		else
			html+="<option value="+j+">"+j+"</option>";
	}
	jQ("tr.clipevent-set_clock td select.time_min").append(html);
}

function detailSetImportant(isvip){
	var eventid=eval(jQ("#clipevent-eventid").val());
	if(isvip){
		jQ("#clipevent-isvip").removeClass().addClass("c_import").attr("title","重要档期");
	}else{
		jQ("#clipevent-isvip").removeClass().addClass("import").attr("title","不重要档期");
	}
	setImport(isvip, eventid);
	serializeClipEventCenterToLeft(eventid);
}

function addClockForDetail(event){
	
	var eventid=eval(jQ("#clipevent-eventid").val());
	var showclock=jQ("tr.clipevent-show_clock");
	var setclock=jQ("tr.clipevent-set_clock");
//	var iconObj=jQ(event.currentTarget);
	if(showclock.css("display")=="none"){
		setclock.hide();
		showclock.show();
		return;
	}
	showclock.hide();
	setclock.show();
	setclock.find("td input:checkbox").attr("checked","true");
	setclock.find("td input.data").val("").datepicker( "destroy" );
	jQ("#alerthour").val(0);
	jQ("#alertmin").val(0);
	setclock.find("td input.data").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		beforeShow: function(i,e){  
		var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
		e.dpDiv.css('z-index', z);  
	}});
	
	
	setclock.find("td button.cancel").unbind("click").bind("click",function(){
		showclock.show();
		setclock.hide();
	});
	setclock.find("td button.confirm").unbind("click").bind("click",function(){
		
		var errzone=jQ("tr.clipevent-clock_info td");
			var alertdateval=jQ(this).prevAll("input:text").val();
			if(alertdateval==null||alertdateval.length<=0){
				errzone.empty();
				errzone.append("请选择提醒的时间。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			
			var alertdate=jQ(this).prevAll("input:text").datepicker( "getDate" );
			var alerthour=eval(jQ("#alerthour").val());
			var alertmin=eval(jQ("#alertmin").val());
			alertdate.setHours(alerthour);
			alertdate.setMinutes(alertmin);
			var alertlong=alertdate.getTime();
			var nowdate=new Date();
			if(alertlong<nowdate){
				errzone.empty();
				errzone.append("提醒的时间应该是将来的时间。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			var isChecked=eval(jQ(this).prevAll("input:checkbox").attr("checked"));
			var mobilenotice=0;
			if(isChecked&&jQ(".hasmobilechoose").css("display")!='none'&&eval(jQ("#var_hasmobile"))){
				mobilenotice=1;
			}
			var btnObj=jQ(this);
			jQ.ajax({
				type: "POST",
				url:"eventAjax!addEventClock.action",
				data:{
					eventid:eventid,
					alerttime:alertlong,
					mobilenotice:mobilenotice
				},
				success:function(data){
					if(data!=null){
						var dataObj=eval("("+data+")");//转换为json对象
						if(dataObj['result']){
							
							setclock.hide();
							showclock.show();
							btnObj.unbind("click");
							jQ("#clipevent-clocktime").val(alertlong);
							jQ("#clipevent-clockicon").removeClass("alarm").addClass("c_alarm").empty().attr("title","取消提醒");
							jQ("#clipevent-clockval").empty().append(formateDetailTime(alertlong));
							jQ("#clipevent-clockicon").unbind("click").bind("click",cancelClockForDetail);
							serializeClipEventCenterToLeft(eventid);
							reloadCacheAndClockCount();
						}else{
						}
					}
				}
			});
	});
}

function cancelClockForDetail(event){
	var eventid=jQ("#clipevent-eventid").val();
	var setclock=jQ("tr.clipevent-set_clock");
	var showclock=jQ("tr.clipevent-show_clock");
	jQ.ajax({
		type: "POST",
		url:"eventAjax!cancelClock.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					setclock.hide();
					showclock.show();
					jQ("#clipevent-clocktime").val(0);
					
					jQ("#clipevent-clockicon").removeClass("c_alarm").addClass("alarm").empty().attr("title","设置提醒");
					jQ("#clipevent-clockval").empty().append("<i>暂无</i>");
					jQ("#clipevent-clockicon").unbind("click").bind("click",addClockForDetail);
					
					serializeClipEventCenterToLeft(eventid);
					reloadCacheAndClockCount();
				}else{
					
				}
			}
		}
	});
}

function initLeftCalendar(){
	jQ("#datepicker").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		onSelect: function(dateText, inst) {
			var selectedDate=Date.parse(dateText);
			if(jQ("div.ms_box[dayattr='"+selectedDate+"']").length>0){
				//已经显示的日期事件去除
				jQ("div.ms_box[dayattr='"+selectedDate+"']").fadeOut("normal",function(){
					   jQ(this).remove();
				 });
				
			}else{
				loadDefinedDateEvents(selectedDate);
				//未显示的日期事件显示
			}
		}
	});//获取日历
//	jQ("#datepicker").children("div").width("254px");//设置日历宽度
	//jQ("#datepicker td").removeAttr("onclick");//移除JQ的原始动作
//	jQ("a.ui-state-default").css("padding","0.4em 0.8em");
//	jQ("a.ui-state-default").click(function(event){
//		if(jQ(this).hasClass("ui-diy-highlight")){
//			jQ(this).removeClass("ui-diy-highlight");//小日历多选功能
//		}else{
//			jQ(this).addClass("ui-diy-highlight");//小日历多选功能
//		}
//	});
}

function loadDefinedDateEvents(addLong){
	jQ.ajax({
		type:"POST",
		url: "manageClipAjax!loadDefinedDateEvents.action",
		data:{
			definedLong:addLong
		},
		success:function(data){
			var mobilenotice=eval(jQ("#var_hasmobile").val());
			organizeData(data,mobilenotice);
		}
	});
}


function loadTodayEvents(){
	jQ.ajax({
		type:"POST",
		url: "manageClipAjax!loadTodayEvents.action",
		success:function(data){
			var mobilenotice=eval(jQ(data).find("mobilenotice").text());
			organizeData(data,mobilenotice);
		}
	});
}

function organizeData(data,mobilenotice){
	var daylong=eval(jQ(data).find("day").text());
	if(jQ(data).find("EventForView").length==0){
		var html="";
		html="<div class='ms_box noeventday' dayattr='"+daylong+"'><div class='ms_tit'><span>"+formateTitleTime(daylong)+"</span><a></a></div><div class='ms_close'><a></a></div><div class='ms_con'><div class='me_list'><i>暂无</i></div></div></div>";
		jQ("#left_clip_list").append(html);
		jQ("#left_clip_list div.ms_box div.ms_tit").unbind("click").bind("click",leftCalendarEventsClick);
		jQ("div.ms_close a").unbind("click").bind("click",leftCalendarRemoveDate);
		return;
	}
	var html="<div class='ms_box ' dayattr='"+daylong+"'><div class='ms_tit'><span>"+formateTitleTime(daylong)+"</span><a></a></div><div class='ms_close'><a></a></div><div class='ms_con'>";
	
	jQ(data).find("EventForView").each(function(){
		var eventid=jQ(this).attr("id");
		var title=jQ(this).find("title").text();
		var eventtype=jQ(this).find("eventtype").text();
		var starttime=eval(jQ(this).find("starttime").text());
		var endtime=eval(jQ(this).find("endtime").text());
		var iswholeday=eval(jQ(this).find("iswholeday").text());
		var address=jQ(this).find("address").text();
		var clocktime=eval(jQ(this).find("clocktime").text());
		var deadlinetime=eval(jQ(this).find("deadlinetime").text());
		var isexpire=eval(jQ("isexpire",this).text());
		var isvip=eval(jQ(this).find("isvip").text());
		var timeattr=eval(jQ(this).attr("timeattr"));
		var processstatus=eval(jQ(this).find("processstatus").text());
		var reliedclip=eval(jQ(this).find("reliedclip").text());
		var publishname=jQ(this).find("publishname").text();
		var forwardname=jQ(this).find("forwardname").text();
		var puid=jQ(this).find("puid").text();
		var fuid=eval(jQ(this).find("fuid").text());
		var cliptype=eval(jQ(this).find("cliptype").text());
		
		var sub="<div class='me_list clipevent-"+eventid+"' cliptype='"+cliptype+"'>";
		sub+="<input type='hidden' class='eventid' value='"+eventid+"'>";
		sub+="<input type='hidden' class='clocktime' value='"+clocktime+"'>";
		sub+="<input type='hidden' class='isvip' value='"+isvip+"'>";
		sub+="<div class='me_item isvip'>";
		sub+="<span class='e_"+eventtype+"' title='"+getTypeName(eventtype)+"'></span>";
		sub+="<span class='title'>"+htmlData(title)+"</span>";
		if(isvip)
			sub+="<span class='c_import isvip' title='标记为不重要'></span>";
		else
			sub+="<span class='import isvip' title='标记为重要'></span>";
		sub+="</div><div class='me_item'>";
		if(reliedclip>0){
			sub+="<span>发起人：</span><span><a href='"+jQ("#ctxVal").val()+"/home/user.html?"+puid+"'>"+publishname+"</a></span>";
		}else
			sub+="<span>发起人：</span><span>"+publishname+"</span>";
		sub+="</div>";
		
		if(fuid>0){
			sub+="<div class='me_item'>";
			sub+="<span>转发人：</span><span><a href='"+jQ("#ctxVal").val()+"/home/user.html?"+fuid+"'>"+forwardname+"</a></span>";
			sub+="</div>";
		}
		sub+="<div class='me_item'>";
		if(iswholeday)
			sub+="<span class='time'><span style='width:auto;'>开始于</span><b>"+formateDetailTime(starttime)+"</b></span>";
		else
			sub+="<span class='time'><b>"+formateDetailTime(starttime)+"</b><i>-</i><b>"+formateDetailTime(endtime)+"</b></span>";
		if(processstatus==0){
			sub+="<b class='edt_ing'>进行中</b>";
		}else if(processstatus==1){
			sub+="<b class=\"edt_over\">已结束</b>";
		}else if(processstatus==2){
			sub+="<b class=\"edt_stop\">已停止</b>";
		}
		sub+="</div><div class='me_item'>";
		sub+="<span>截止：</span><span>";
		if(deadlinetime>0){
			sub+=formateDetailTime(deadlinetime);
			if(isexpire)
				sub+="<b class='expire'>已过期</b>";	
		}
		else
			sub+="<i>暂无</i>";
		sub+="</span>";
		
		sub+="</div><div class='me_item'>";
		sub+="<span>地址：</span><span class='adr'>"+htmlData(address)+"</span>";
		sub+="</div><div class='me_item me_clock show_clock'>";
		sub+="<span>提醒：</span>";
		if(clocktime>0){
			sub+="<span class='alarm clockval'>"+formateDetailTime(clocktime);
		}else{
			sub+="<span class='clockval'><i>暂无</i>";
		}
		sub+="</span>";
		sub+="</div><div class='me_item me_clock set_clock' style='display:none;'>";
		sub+="<span>提醒</span>";
		sub+="<input style='margin:0 5px;width:130px;' type='text' size='15' class='data'>";
		sub+="<div class='timebg hourbg'><a class='minus' onclick='hourminus(jQ(this).next());'></a>" +
				"<input maxlength='2' value='0' onblur='hourinput(this);' class='alert_hour'/>" +
				"<a class='plus' onclick='hourplus(jQ(this).prev());'></a></div>" +
				"<span class='tipt'>时</span>";
		sub+="<div class='timebg minbg'><a class='minus' onclick='minminus(jQ(this).next());'></a>" +
				"<input maxlength='2' value='0' onblur='mininput(this);' class='alert_min'/>" +
				"<a class='plus' onclick='minplus(jQ(this).prev());'></a></div>" +
				"<span class='tipt'>分</span>";
		if(mobilenotice)
			sub+="<input type='checkbox' class='hasmobilechoose' style='float:left;margin-top:8px;'/><img src='"+jQ("#ctxVal").val()+"/image/mobilemsg.png' width='16px' height='16px' style='float:left;margin-top:5px;' class='hasmobilechoose' alt='手机短信提醒' title='手机短信提醒'/>";
		sub+="<button>确定</button></div><div class='me_item set_clock_info' style='color:#ff0000;'></div><div class='me_item opt_item'>";
		if(reliedclip>0){
			if(processstatus==0)
				sub+="<a class='delicon f_leave' title='退出档期' style='margin-right:13px;'></a>";
			else
				sub+="<a class='delicon f_leave' title='删除档期' style='margin-right:13px;'></a>";
		}else{
			sub+="<a class='delicon f_del' title='取消档期' style='margin-right:13px;'></a>";
		}
		sub+="<a class='f_info' title='档期详情'></a>";
		if(clocktime>0){
			sub+="<a class='alarmicon f_c_alarm' title='取消提醒' ></a>";
		}else{
			sub+="<a class='alarmicon f_alarm' title='设置提醒' ></a>";
		}
		sub+="</div></div>";
		
		html+=sub;
	});
	html+="</div></div>";
	jQ("#left_clip_list").append(html);
	jQ("#left_clip_list div.ms_box div.ms_tit").unbind("click").bind("click",leftCalendarEventsClick);
	jQ("div.ms_con div.me_list div.isvip span.isvip").unbind("click").bind("click",leftCalendarSetImport);
	jQ("div.ms_con div.me_list div.opt_item a.delicon").unbind("click").bind("click",leftCalendarDeleteEvent);
	jQ("div.ms_con div.me_list div.opt_item a.f_info").unbind("click").bind("click",function(event){
		var eventid=jQ(event.currentTarget).parent().prevAll("input.eventid").val();
		window.location.href=jQ("#ctxVal").val()+"/myclip/clip_detail.html?eventid="+eventid;
	});
	jQ("div.ms_con div.me_list div.opt_item a.alarmicon").unbind("click").bind("click",function(event){
		if(jQ(this).hasClass("f_c_alarm")){
			leftCalendarCancelClock(event);
		}else if(jQ(this).hasClass("f_alarm")){
			leftCalendarAddClockAtLeft(event);
		}
	});
	
	jQ("div.ms_close a").unbind("click").bind("click",leftCalendarRemoveDate);
	
}

function leftCalendarAddClockAtLeft(event){
	var eventid=jQ(event.currentTarget).parent().prevAll("input.eventid").val();
	var showclock=jQ(event.currentTarget).parent().prevAll("div.show_clock");
	var setclock=jQ(event.currentTarget).parent().prevAll("div.set_clock");
//	var iconObj=jQ(event.currentTarget);
	if(showclock.css("display")=="none"){
		jQ(event.currentTarget).parent().prevAll("div.set_clock_info").empty().hide();
		setclock.hide();
		showclock.show();
		return;
	}
	showclock.hide();
	setclock.show();
	setclock.find("input:checkbox").attr("checked","true");
	setclock.find("input.data").val("");
	setclock.find("input.alert_hour").val(0);
	setclock.find("input.alert_min").val(0);
	setclock.find("input.data").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		beforeShow: function(i,e){  
		var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
		e.dpDiv.css('z-index', z);  
	}});
	
	
	setclock.find("button").unbind("click").bind("click",function(){
		
		var isChecked=eval(jQ(this).prevAll("input:checkbox").attr("checked"));
		var errzone=jQ(this).parent().nextAll("div.set_clock_info");
			var alertdateval=jQ(this).prevAll("input:text").val();
			if(alertdateval==null||alertdateval.length<=0){
				errzone.empty();
				errzone.append("请选择提醒的时间。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			
			var alertdate=jQ(this).prevAll("input:text").datepicker( "getDate" );
			var alerthour=eval(jQ(this).prevAll("div.hourbg").find("input.alert_hour").val());
			var alertmin=eval(jQ(this).prevAll("div.minbg").find("input.alert_min").val());
			alertdate.setHours(alerthour);
			alertdate.setMinutes(alertmin);
			var alertlong=alertdate.getTime();
			var nowdate=new Date();
			if(alertlong<nowdate){
				errzone.empty();
				errzone.append("提醒的时间应该是将来的时间。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			var mobilenotice=0;
			var checked=eval(jQ(this).prevAll("input:checkbox").attr("checked"));
			if(eval(jQ("#var_hasmobile"))&&checked){
				mobilenotice=1;
			}
			var btnObj=jQ(this);
			jQ.ajax({
				type: "POST",
				url:"eventAjax!addEventClock.action",
				data:{
					eventid:eventid,
					alerttime:alertlong,
					mobilenotice:mobilenotice
				},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj['result']){
						
						setclock.hide();
						showclock.show();
						btnObj.unbind("click");
						jQ("div.clipevent-"+eventid+" input.clocktime").val(alertlong);
						var ss=jQ("div.clipevent-"+eventid+" div.show_clock span.clockval");
						ss.addClass("alarm").empty().append(formateDetailTime(alertlong));
						var ss2=jQ("div.clipevent-"+eventid+" div.opt_item a.alarmicon");
						ss2.removeClass("f_alarm").addClass("f_c_alarm").attr("title","取消提醒");
						ss2.unbind("click").bind("click",leftCalendarCancelClock);
						serializeClipEventLeftToCenter(eventid);
						reloadCacheAndClockCount();
					}else{
					}
				}
			}
			});
	});
}

function leftCalendarCancelClock(event){
	var eventid=jQ(event.currentTarget).parent().prevAll("input.eventid").val();
	var setclock=jQ(event.currentTarget).parent().prevAll("div.set_clock");
	var showclock=jQ(event.currentTarget).parent().prevAll("div.show_clock");
	var iconObj=jQ(event.currentTarget);
	jQ.ajax({
		type: "POST",
		url:"eventAjax!cancelClock.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					setclock.hide();
					showclock.show();
					jQ("div.clipevent-"+eventid+" input.clocktime").val(0);
					var ss=jQ("div.clipevent-"+eventid+" div.show_clock span.clockval");
					ss.removeClass("alarm").empty().append("<i>暂无</i>");
					var ss2=jQ("div.clipevent-"+eventid+" div.opt_item a.alarmicon");
					ss2.removeClass("f_c_alarm").addClass("f_alarm").attr("title","设置提醒");
					ss2.unbind("click").bind("click",leftCalendarAddClockAtLeft);
					serializeClipEventLeftToCenter(eventid);
					reloadCacheAndClockCount();
				}else{
					
				}
			}
		}
	});
}

function leftCalendarRemoveDate(event){
	var curObj=jQ(event.currentTarget);
	curObj.parent().parent().fadeOut("normal",function(){
		   jQ(this).remove();
	 });
}

function leftCalendarDeleteEvent(event){
	var curObj=jQ(event.currentTarget);
	var info="";
	var title="";
	if(curObj.hasClass("f_leave")){
		var cliptypenode=curObj.parent().parent();
		var cliptype=eval(cliptypenode.attr("cliptype"));
		if(cliptype==3){
			info="您确定退出档期么？<p>分享档期将不被保存在回收站内";
		}else
			info="您确定退出档期么？";
		title="退出档期";
	}else if(curObj.hasClass("f_del")){
		info="您确定取消档期么？";
		title="取消档期";
	}
	var eventid=curObj.parent().prevAll("input.eventid").val();
	jQ("#viewopt_eventid").val(eventid);
	var opt=jQ("#viewopt");
	opt.bind("deleteEvent",deleteEventAtLeftCalendar);
	opt.data("function","deleteEvent")
	jQ("#viewopt_p").empty().append(info);
	jQ("#viewopt").dialog( "option", "title", title);
	jQ("#viewopt").dialog("open");
}

function leftCalendarEventsClick(event){
	var curObj=jQ(event.currentTarget);
	if(curObj.find("a").hasClass("expend")){
		curObj.find("a").removeClass("expend");
		curObj.nextAll("div.ms_con").slideUp();
	}else{
		curObj.find("a").addClass("expend");
		curObj.nextAll("div.ms_con").slideDown();
	}
}

function leftCalendarSetImport(event){
	var curObj=jQ(event.currentTarget);
	var eventid=eval(curObj.parent().prevAll("input.eventid").val());
	var ss=jQ("div.clipevent-"+eventid+" div.isvip span.isvip");
	if(curObj.hasClass("c_import")){
		
		ss.removeClass("c_import").addClass("import");
		ss.attr("title","标记为重要");
		jQ("div.clipevent-"+eventid+" input.isvip").val(0);
		setImport(false,eventid);
	}else if(curObj.hasClass("import")){
		
		ss.removeClass("import").addClass("c_import");
		ss.attr("title","标记为不重要");
		jQ("div.clipevent-"+eventid+" input.isvip").val(1);
		setImport(true,eventid);
	}
	serializeClipEventLeftToCenter(eventid);
	
}

function serializeClipEventLeftToCenter(eventid){
	var leftObjs=jQ("div.clipevent-"+eventid);
	if(leftObjs.length==0){
		if(eventid==eval(jQ("#clipevent-eventid").val())){
			backPage();
		}
		return;
	}
	var isvip=eval(leftObjs.find("input.isvip").val());
	var clocktime=eval(leftObjs.find("input.clocktime").val());
	
	if(isvip){
		jQ("#clipevent-isvip").removeClass().addClass("c_import").attr("title","重要档期");
	}else{
		jQ("#clipevent-isvip").removeClass().addClass("import").attr("title","不重要档期");
	}
	
	jQ("#clipevent-clocktime").val(clocktime);
	if(clocktime>0){
		jQ("#clipevent-clockicon").removeClass("alarm").addClass("c_alarm").empty().attr("title","取消提醒");
		jQ("#clipevent-clockval").empty().append(formateDetailTime(clocktime));
		jQ("#clipevent-clockicon").unbind("click").bind("click",cancelClockForDetail);
	}else{
		jQ("#clipevent-clockicon").removeClass("c_alarm").addClass("alarm").empty().attr("title","设置提醒");
		jQ("#clipevent-clockval").empty().append("<i>暂无</i>");
		jQ("#clipevent-clockicon").unbind("click").bind("click",addClockForDetail);
	}
}

function serializeClipEventCenterToLeft(eventid){
	var isvip=jQ("#clipevent-isvip").hasClass("import")?0:1;
	var clocktime=eval(jQ("#clipevent-clocktime").val());
	var leftObjs=jQ("div.clipevent-"+eventid);
	leftObjs.find("input.clocktime").val(clocktime);
	leftObjs.find("input.isvip").val(isvip);
	if(isvip)
		leftObjs.find("div span.isvip").removeClass("import").addClass("c_import").attr("title","标记为不重要");
	else
		leftObjs.find("div span.isvip").removeClass("c_import").addClass("import").attr("title","标记为重要");
	var alarmobj=leftObjs.find("div.opt_item a.alarmicon");
	if(clocktime>0){
		leftObjs.find("div.show_clock span.clockval").addClass("alarm").empty().append(formateDetailTime(clocktime));
		alarmobj.removeClass("f_alarm");
		if(!alarmobj.hasClass("f_c_alarm"))
			alarmobj.addClass("f_c_alarm");
		alarmobj.attr("title","取消提醒");
		alarmobj.unbind("click").bind("click",leftCalendarCancelClock);
	}else{
		leftObjs.find("div.show_clock span.clockval").removeClass("alarm").empty().append("<i>暂无</i>");
		alarmobj.removeClass("f_c_alarm");
		if(!alarmobj.hasClass("f_alarm"))
			alarmobj.addClass("f_alarm");
		alarmobj.attr("title","设置提醒");
		alarmobj.unbind("click").bind("click",leftCalendarAddClockAtLeft);
	}
}

function deleteEventAtLeftCalendar(){
	var eventid=jQ("#viewopt_eventid").val(); 
	jQ.ajax({
		type: "POST",
		url:"eventAjax!deleteEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#viewopt").dialog("close");
					jQ("div.clipevent-"+eventid).remove();
					noeventInLeftCalendar();
//					noeventInLeft();
					serializeClipEventLeftToCenter(eventid);
				}else{
					jQ("#viewopt_p").empty().append(dataObj['msg']);
					jQ("#viewopt").dialog("close");
				}
			}
		}
	});
}

function noeventInLeftCalendar(){
	var tmp="";
	jQ("#left_clip_list div.ms_box").each(function(){
		if(jQ(this).find("div.ms_con div").length==0){
			tmp="<div class='me_list'><i>暂无</i></div>";
			jQ(this).find("div.ms_con").empty().append(tmp);
		}
	});
}

function setImport(isImport,eventid){
	jQ.ajax({
		type: "POST",
		url:"eventAjax!setEventImport.action",
		data:{
			isImport:Number(isImport),
			eventid:eval(eventid)
		},
		success:function(data){
		}
	});
}

function backPage(){
	var currentpage=eval(getParameter("currentpage"));
	if(isNaN(currentpage)||currentpage==null){
		window.location.href=jQ("#ctxVal").val()+"/myclip/clip_remind.html";
	}else{
		window.location.href=jQ("#ctxVal").val()+"/myclip/clip_remind.html?currentpage="+currentpage;
	}
}

function formateDetailTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy-MM-dd HH:mm");
}

function formateTitleTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy年MM月dd日");
}

function getTypeName(eng){
	if(eng=='other'){
		return "其他";
	}else if(eng=='work'){
		return "工作";
	}else if(eng=='socal'){
		return "社交";
	}else if(eng=='sect'){
		return "私人";
	}
}

function getParameter(name){
    var paramStr=location.search;
    if(paramStr.length==0)return null;
    if(paramStr.charAt(0)!='?')return null;
    paramStr=decodeURIComponent(paramStr);
    paramStr=paramStr.substring(1);
    if(paramStr.indexOf("#")>0){
    	paramStr=paramStr.substring(0,paramStr.indexOf("#"));
    }
    if(paramStr.length==0)return null;
    var params=paramStr.split('&');
    var p = null;
    for(var i=0;i<params.length;i++){
        if(params[i].indexOf(name) >= 0){
            p = params[i].split('=');
            p = p[1];
        }
    }
    return p;
}